package com.idis.dbApp.controller;

import com.idis.dbApp.mapper.WorkMapper;
import com.idis.entity.User;
import com.idis.entity.Work;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by Ming on 2018/1/29.
 */
@RestController
@RequestMapping("/work")
@Api(tags = "作品接口")
public class WorkController {

    @Autowired
    WorkMapper workMapper;

    @ApiOperation("获取所有作品信息")
    @GetMapping("/all")
    public List<Work> finAllWork(){
        return workMapper.findAll();
    }

    @ApiOperation("新增作品")
    @PostMapping("/save")
    public int saveWork(@ApiParam("作品信息")@RequestBody Work work){
        return workMapper.insert(work);
    }

    @ApiOperation("更新作品的非空属性")
    @PostMapping("/updatenull")
    public Integer updateNotNull(@ApiParam("作品信息")@RequestBody Work work){
        return workMapper.updateByPrimaryKeySelective(work);
    }

    @ApiOperation("更新作品")
    @PostMapping("/update")
    public Integer update(@ApiParam("作品信息")@RequestBody Work work){
        return workMapper.updateByPrimaryKey(work);
    }

    @ApiOperation("根据作品属性搜索作品")
    @PostMapping("/findbyproperty")
    public List<Work> findByProperty(@ApiParam("要搜索的作品信息，若该信息不需要被用于搜索则可置空该属性")@RequestBody Work work){
        return workMapper.findByProperty(work);
    }

    @ApiOperation("根据作品类型搜索作品")
    @PostMapping("/findbytype")
    public List<Work> findByType(@ApiParam("作品类型代号")@RequestBody Integer type){
        return workMapper.findByType(type);
    }

    @ApiOperation("根据作品名称模糊搜索作品")
    @PostMapping("/findlikename")
    public List<Work> findLikeName(@ApiParam("作品名称")@RequestBody String name){
        return workMapper.findLikeName(name);
    }

    @ApiOperation("删除作品")
    @PostMapping("/delete")
    public Integer delete(@ApiParam("作品信息,需要且仅需要作品ID")@RequestBody Work work){
        return workMapper.deleteByPrimaryKey(work.getId());
    }

}
